<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增游戏信息')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-game-add">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">游戏名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">游戏简介：</label>
                <div class="col-sm-8">
                    <input name="intro" class="form-control" type="text" required>
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">游戏标签：</label>
                <div class="col-sm-8">
                    <div class="input-group">
<!--                        <input id="treeId" name="tag" type="hidden"/>-->
                        <input class="form-control" type="text" onclick="selectTagTree()" id="tags" required>
                        <input class="form-control" type="hidden" name="tagsHidden" id="tagsHidden" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">游戏大小(字节)：</label>
                <div class="col-sm-8">
                    <input name="size" class="form-control" type="text" required>
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">游戏评分(满分5分)：</label>
                <div class="col-sm-8">
                    <input name="score" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">游戏版本号：</label>
                <div class="col-sm-8">
                    <input name="version" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">游戏语言：</label>
                <div class="col-sm-8">
                    <input name="lang" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">运行环境：</label>
                <div class="col-sm-8">
                    <input name="runEnv" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">解压码：</label>
                <div class="col-sm-8">
                    <input name="password" class="form-control" type="text">
                </div>
            </div>
        </div>
        <div class="col-xs-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "biz/game"
    $("#form-game-add").validate({
        focusCleanup: true
    });

    function selectTagTree() {
        var options = {
            title: '游戏标签选择',
            width: "480",
            url: prefix + "/toTree/",
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        var originCheck = body.find('#selectNodeJson');
        // console.log(originCheck);
        // console.log(originCheck[0].innerHTML);

        var html = originCheck[0].innerHTML;
        if (html !== undefined && html !== '') {
            var json = JSON.parse(html);
            // console.log(json);
            // 前台显示标签
            $("#tags").val(json.map(node => node.name).join(","));
            // 把id传给后台
            $("#tagsHidden").val(json.map(node => node.id).join(","));
        }

        $.modal.close(index);
    }


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-game-add').serialize());
        }
    }
</script>
</body>
</html>